<template>
  <div class="collect">
    <nav-bar title="我的收藏"></nav-bar>
    <p class="collect-title">我的收藏</p>
    <ul class="list">
      <li
        class="item"
        v-for="item in collectList"
        :key="item.id"
        @click="toGoods(item.id)"
      >
        <img :src="item.list_pic_url" alt="" />
        <p class="name">{{ item.name }}</p>
        <p class="price">￥ {{ item.retail_price }}</p>
      </li>
      <li class="item"></li>
    </ul>
  </div>
</template>

<script>
import NavBar from "@/components/common/nav-bar";
import { getCollectList } from "@/api/pages/collect";
export default {
  data() {
    return {
      collectList: [],
    };
  },
  methods: {
    getData() {
      let openId = localStorage.getItem("openId");
      getCollectList({ openId }).then((res) => {
        console.log(res);
        this.collectList = res.collectGoodsList;
      });
    },

    toGoods(id){
      this.$router.push({path:'/pages/goods/goods',query:{id}});
    }
  },
  created() {
    this.getData();
  },
  components: {
    "nav-bar": NavBar,
  },
};
</script>

<style lang="scss" scoped>
.collect {
  .collect-title {
    margin: 2px 0;
    width: 100%;
    height: 44px;
    line-height: 44px;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    background-color: #fff;
  }

  .list {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    .item {
      margin: auto;
      margin-bottom: 5px;
      width: 48%;
      height: 210px;
      background-color: #fff;
      .name {
        margin-left: 10px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
      .price {
        margin-left: 10px;
        margin-top: 16px;
        color: #9c3232;
      }
      img {
        display: block;
        margin: 0 auto;
        width: 150px;
        height: 150px;
      }
      .last-title {
        margin-top: 40px;
        font-size: 16px;
        text-align: center;
      }
      .last-img {
        margin-top: 40px;
        width: 35px;
        height: 35px;
      }
    }

    .item:nth-last-child(1) {
      height: 0px;
    }
  }
}
</style>